<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <link rel="stylesheet" href="/dev/plugins/bootstrap/css/bootstrap.css">
    <style>
        #pagination {
            margin-top: 20px;
            margin-bottom: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        #pagination button {
            margin: 0 5px;
        }
        .movie-item {
            margin-bottom: 20px;
        }
        .movie-item img {
            max-width: 100%;
        }
        .movie-item h4 {
            margin: 10px 0;
        }
    </style>
</head>
<body>

<div class="container">
    <h3>搜索结果</h3>
    <div id="movie-list"></div>
    <div id="pagination">
        <!-- 分页 -->
        <button id="prev-btn" class="btn btn-secondary" disabled>上一页</button>
        <button id="next-btn" class="btn btn-secondary">下一页</button>
    </div>
</div>

<script src="/dev/plugins/jquery/jquery.min.js"></script>
<script>
    var currentPage = 1;  // 当前页码
    var totalPages = 1;   // 总页数

    $(document).ready(function () {
        loadStarImage();
    });

    function loadStarImage() {
        $.ajax({
            url: '/dev/userMovies/my/star',
            type: 'GET',
            data: {page: currentPage, pageSize: 5},
            contentType: 'application/json',
            headers: {
                'Authorization': localStorage.getItem('token')
            },
            success: function (res) {
                if (res.code == 1) {
                    // 显示电影列表
                    let movieHtml = '';
                    res.data.list.forEach(function (movie) {
                        movieHtml += `
                        <div class="movie-item">
                            <img src="${movie.post}" alt="${movie.name}" class="img-thumbnail" style="width: 150px;">
                            <h4>${movie.name} (${movie.year})</h4>
                            <p>导演: ${movie.director}</p>
                            <p>评分: ${movie.score}</p>
                            <a href="${movie.torrent}" target="_blank" class="btn btn-primary">下载</a>
                        </div>
                    `;
                    });
                    $('#movie-list').html(movieHtml);

                    // 更新分页
                    totalPages = res.data.total || 1;
                    updatePagination();
                } else if (res.code == 0) {
                    alert(res.msg);
                }
            },
            error: function (err) {
                console.error("请求失败", err);
            }
        });
    }

    // 更新分页按钮状态
    function updatePagination() {
        $('#prev-btn').prop('disabled', currentPage <= 1);
        $('#next-btn').prop('disabled', currentPage > totalPages / 5);
    }

    // 上一页按钮点击事件
    $('#prev-btn').click(function() {
        if (currentPage > 1) {
            currentPage--;
            loadMovies(currentPage, currentKeyword);
        }
    });

    // 下一页按钮点击事件
    $('#next-btn').click(function() {
        if (currentPage < totalPages) {
            currentPage++;
            loadMovies(currentPage, currentKeyword);
        }
    });
</script>
</body>
</html>